package com.yu;

import com.yu.service.HelloService;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;

public class Client {
    public static void main(String[] args) {

        //创建cxf代理工厂
        JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
        //设置远程访问的地址
        factory.setAddress("http://localhost:8010/ws/hello");


        //设置接口类型
        factory.setServiceClass(HelloService.class);

        //对接口生成代理对象
        HelloService helloService = factory.create(HelloService.class);
        //控制台打印对象信息， 代理对象 class com.sun.proxy.$Proxy34 Java代理：1静态代理 2动态代理（Jdk接口代理，cglib子类代理） ￥CGLIB
        System.out.println(helloService.getClass());


        //远程访问服务端方法
        String content = helloService.sayHello("Jet");
        System.out.println(content);


        //日志输入
        factory.getInInterceptors().add(new LoggingInInterceptor());
        //日志输出
        factory.getOutFaultInterceptors().add(new LoggingOutInterceptor());

    }
}
